<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once 'database.php';
require 'login_reg.php';
require 'photo_handler.php';

//ubah password
if (isset($_POST['SubmitUserAndPassword'])){
    $usr = $_POST['UserName'];
    $new_pwd = $_POST['Password'];
    $query = "SELECT usr_email FROM user WHERE usr_email='$usr'";

    $db = new login_reg();
    $db->connect();
    if (mysql_num_rows(mysql_query($query,$db->conn)) > 0){
        $db->change_password($usr, $new_pwd);
         header('Location: ../admin.php');
    }
    else{
      header('Location: ../admin.php?gagal=1');

    }
}

//block user
if (isset($_POST['SubmitBlockUserName'])){
    $usr = $_POST['BlockUserName'];

    $query0 = "SELECT usr_email FROM user WHERE usr_email='$usr'";
    $query = "UPDATE user SET status=0 WHERE usr_email='$usr'";
    
    $db = new database();
    $db->connect();
    if (mysql_num_rows(mysql_query($query0,$db->conn)) > 0){
        
        mysql_query($query,$db->conn);
        header('Location: ../admin.php');
    }
    else{
      header('Location: ../admin.php?gagal=1');
    }
    mysql_close();
}

//hapus foto
if (isset($_POST['SubmitBlockUserPhoto'])){
    $photo_id = $_POST['BlockUserPhoto'];

    $query0 = "SELECT photo_id FROM photo WHERE photo_id=$photo_id";
    $db = new database();
    $db->connect();

    if (mysql_num_rows(mysql_query($query0,$db->conn)) > 0){
        $ph = new photo_handler();
        $ph->delete_photo($photo_id);
        header('Location: ../admin.php');
    }
    else{
      header('Location: ../admin.php?gagal=1');
    }

}
?>
